<circuit access="public" xmlns:cs="coldspring/">

	<fuseaction name="login">
		<set name="attributes.isLoginForm" value="true" />
		<xfa name="frmSubmit" value="validateLogin" />
		<do action="v.loginForm" contentvariable="pageContent" />
	</fuseaction> 
	
	<fuseaction name="validateLogin">	
		<cs:get bean="PersonnelService"
					 returnvariable="variables.personnelService"
					 coldspringfactory="serviceFactory" />
					 
		<cs:get bean="Security"
					 returnvariable="variables.security"
					 coldspringfactory="serviceFactory" />
					 
		<invoke object="variables.personnelService" method="getPersonnel" returnVariable="variables.person" >
			<argument name="uname" value="#attributes.username#" />
			<argument name="pword" value="#attributes.password#" />
		</invoke>	 
		
		<if condition="variables.person.personnelid GT 0">
			<true>
				<invoke object="variables.security" method="initializeUser">
					<argument name="user" value="#variables.person#" />
				</invoke>
				<relocate url="#self#" />
			</true>
			<false>
				<do action="login" />
			</false>
		</if>
	</fuseaction>
	
	<fuseaction name="logout">
		<set name="client.IsAuthenticated" value="FALSE" />
		<relocate url="#myself#security.login" />
	</fuseaction>

	<fuseaction name="checkAuthentication">
		<if condition="NOT (IsDefined('client.IsAuthenticated') AND client.IsAuthenticated)">
			<true>
				<xfa name="login" value="login" overwrite="false"/>
				<relocate url="#myself##xfa.login#"/>
			</true>
		</if>
	</fuseaction>
	
</circuit>